package com.yenlien.traceyun.control.dao;

import com.yenlien.traceyun.control.entity.ModelClassify;
import com.yenlien.traceyun.webase.dao.BaseJpaDao;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * Created by LiuSha on 2020/3/20.
 */
public interface ModelClassifyDao extends BaseJpaDao<ModelClassify> {
    ModelClassify findById(String id);

    @Query(value = "select * from t_model_classify where parent_id = ?1 ORDER BY sort ", nativeQuery = true)
    List<ModelClassify> findByParentId(String parentId);

    @Query(value = "select * from t_model_classify where type = 0 ORDER BY sort ", nativeQuery = true)
    List<ModelClassify> findByOne();

    @Query(value = "select m.name from ModelClassify m where m.id=?1")
    String getByName(String id);

    @Query(value = "select * from t_model_classify where type = 0  and id in ( select  cm.modelclassify_id from t_company_modelclassify cm where cm.company_id =?1) ORDER BY sort ", nativeQuery = true)
    public List<ModelClassify> findByCompanyId(String companyId);

}
